﻿Imports System.Data.OleDb
Partial Public Class UserPage
    Inherits System.Web.UI.Page
    Dim Uid As Int16
    Dim Vname As String
    Dim CountLike As Int16
    Dim CountComment As Int16
    Dim TotalContribution As Int16

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.lbl_UserName.Text = User.Identity.Name

        findUSerID()
        loadUserInfo()

        If check_the_importanceofiser() = True Then
            Me.GridView2.Visible = True
            Me.lbl_showerror.Text = ""
        Else
            Me.GridView2.Visible = False
            Me.lbl_showerror.Text = "Sorry you cant see the recent visitors of yours.."
        End If
    End Sub

    Function findUSerID()
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        con.Open()

        Dim oledbcmd As New OleDbCommand("SELECT * From aspnet_Users where UserName = @Username", con)
        oledbcmd.Parameters.AddWithValue("@Username", User.Identity.Name)
        Dim dr As OleDbDataReader = oledbcmd.ExecuteReader()
        dr.Read()
        Uid = dr("UserId")
        Me.Uid_lbl.Text = Uid
        Return Uid
    End Function

    Sub loadUserInfo()
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        Try
            con.Open()

            Dim oledbcmd As New OleDbCommand("SELECT * From UserDetails where UserName ='" + User.Identity.Name + "'", con)
            Dim dr As OleDbDataReader = oledbcmd.ExecuteReader()
            dr.Read()
            Me.UserProfileIMG.ImageUrl = dr("Photo")
        Catch ex As Exception
        End Try
    End Sub


    Function check_the_importanceofiser() As Boolean
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        Dim SltQRY As String = "Select * from Likes_tbl where user_ID = " & findUSerID() & ""
        con.Open()

        Dim cmd As New OleDbCommand(SltQRY, con)

        Dim dr As OleDbDataReader = cmd.ExecuteReader()
        If dr.HasRows Then
            While dr.Read

                CountLike += 1

            End While
        End If
        con.Close()


        ' count total comment by the user
        Dim SltQRY1 As String = "Select * from Comments where UserName = '" + User.Identity.Name + "'"
        con.Open()

        Dim cmd1 As New OleDbCommand(SltQRY1, con)

        Dim dr1 As OleDbDataReader = cmd1.ExecuteReader()
        If dr1.HasRows Then
            While dr1.Read

                CountComment += 1

            End While
        End If
        TotalContribution = CountComment + CountLike
        If TotalContribution > 3 Then
            Return True
            MsgBox("Tue")
        Else
            Return False
        End If

    End Function

  

   
    Protected Sub Img_rssDiscussionBTN_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Img_rssDiscussionBTN.Click
        Response.Redirect("RssDisscussions.aspx")
    End Sub
End Class